home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Visual Basic Controls
/
Visual Basic Controls.iso
/
vbcontrol
/
edgetext
/
clscompa.cl_
/
clscompa.cl
Encoding:
Amiga
Atari
Commodore
DOS
FM Towns/JPY
Macintosh
Macintosh JP
Macintosh to JP
NeXTSTEP
RISC OS/Acorn
Shift JIS
UTF-8
Wrap
Visual Basic class definition
|
1998-06-27
|
37.6 KB
|
1,124 lines
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
END
Attribute VB_Name = "clsCompany"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit
'**************************************************************************************
'Title: clsCompany.cls
'Author: DesignGrid by W. David Ewing, Copyright 1998
'Purpose: This class allows single record access to the Company Table
'Properties:Equate to the fields in the table
'Methods: Allow for record manipulation
'This is commented because it is recommended that objError be declared global
'The reason for this is so that the DisplayFlag and writeToFile properties will
'be persistent
'Private objError as new clsError
'It is recommended that the Database object Dbtimesheet be declared global
'It is also recommended that the Configuration object be declared global if it is being used
'This is so that it can be persistent
'**************************************************************************************
'Here are the Field Properties for this table Class
Public Company_Id As Integer
Public Company_Name As String
Public Address1 As String
Public Address2 As String
Public City As String
Public State As String
Public Zip As String
Public Phone As String
Public Fax As String
Public Contact As String
Public Updated_By As String
Public Update_Module As String
Public Update_Time As String
'These are the ScratchPad Variables
Private mCompany_Id As Integer
Private mCompany_Name As String
Private mAddress1 As String
Private mAddress2 As String
Private mCity As String
Private mState As String
Private mZip As String
Private mPhone As String
Private mFax As String
Private mContact As String
Private mUpdated_By As String
Private mUpdate_Module As String
Private mUpdate_Time As String
'This public variable tells whether a function was successful, it is True when a function
'is successful, and false when a function is unsuccessful
Public Success As Boolean
'This is the Error Code which was generated in the function call, it matches Err from VB
Public ErrorCode As Double
'This is the Error message which was generated in the function call, it matches Errors(0) VB
Public ErrorMessage As String
'********************************************************************************************************
'Title: CreateTable
'Author: DesignGrid by W. David Ewing, Copyright 1998
'Purpose: This subroutine Creates the very table that this class was created to read and write
'Parameters:None
'Return: Nothing
'********************************************************************************************************
Public Sub CreateTable()
Dim lsSelect As String
Dim RetCode As Integer, liCount As Integer, BadCount As Integer
'The Success flag gets initialized to True and set to false if a trappable error occurs
Success = True
'The ErrorCode is the Err returned by VB for the Trapped Error
ErrorCode = False
'The DebugFlag is the provision which turns off all error checking in the table class when false
If Not objConfiguration.DebugFlag Then
On Error GoTo NoCompanyCreateTable
End If
'Assemble the SQL String
lsSelect = "Create Table COMPANY ("
lsSelect = lsSelect & "Company_Id Integer(2),"
lsSelect = lsSelect & "Company_Name String(100),"
lsSelect = lsSelect & "Address1 String(50),"
lsSelect = lsSelect & "Address2 String(50),"
lsSelect = lsSelect & "City String(50),"
lsSelect = lsSelect & "State String(2),"
lsSelect = lsSelect & "Zip String(10),"
lsSelect = lsSelect & "Phone String(50),"
lsSelect = lsSelect & "Fax String(50),"
lsSelect = lsSelect & "Contact String(100),"
lsSelect = lsSelect & "Updated_By String(50),"
lsSelect = lsSelect & "Update_Module String(50),"
lsSelect = lsSelect & "Update_Time Date/Time(8))"
'Execute the SQL
dbTimeSheet.Execute lsSelect
On Error GoTo 0
Exit Sub
NoCompanyCreateTable:
Success = False
ErrorCode = Err
objError.ErrorCode = Err
objError.FunctionName = "clsCompany.CreateTable"
If Err = 3146 Then
objError.Message = "Company, CreateTable " & vbCrLf & Errors(0) & " "
ErrorMessage = Errors(0)
Else
objError.Message = "Company, CreateTable "
ErrorMessage = Error(Err)
End If
objError.SQL = lsSelect
objError.Display vbExclamation
Resume Next
End Sub
'********************************************************************************************************
'Title: AddItem
'Author: DesignGrid by W. David Ewing, Copyright 1998
'Purpose: This method Adds Items to the Database after the Key properties
' of the class have been filled
'Parameters:None
'Return: Nothing
'********************************************************************************************************
Public Sub AddItem()
Dim lsSelect As String
Dim RetCode As Integer, liCount As Integer, BadCount As Integer
'The Success flag gets initialized to True and set to false if a trappable error occurs
Success = True
'The ErrorCode is the Err returned by VB for the Trapped Error
ErrorCode = False
'The DebugFlag is the provision which turns off all error checking in the table class when false
If Not objConfiguration.DebugFlag Then
On Error GoTo NoCompanyAddItem
End If
'First we assign all the properties to temp vars and set any blank dates to NULL, or put in the date delimiters (Database Dependent)
StoreProperties
SetDefaultDates
'Now Pad fields with a space if the record cannot be added with zero length
PadFields
'The Double Your Quotes routine doubles any single quotes in string type variables for SQL compatibility
DoubleYourQuotes
'Assemble the SQL String
lsSelect = "Insert into COMPANY ("
'First the Field List
lsSelect = lsSelect & "Company_Id,"
lsSelect = lsSelect & "Company_Name,"
lsSelect = lsSelect & "Address1,"
lsSelect = lsSelect & "Address2,"
lsSelect = lsSelect & "City,"
lsSelect = lsSelect & "State,"
lsSelect = lsSelect & "Zip,"
lsSelect = lsSelect & "Phone,"
lsSelect = lsSelect & "Fax,"
lsSelect = lsSelect & "Contact,"
lsSelect = lsSelect & "Updated_By,"
lsSelect = lsSelect & "Update_Module,"
lsSelect = lsSelect & "Update_Time)"
lsSelect = lsSelect & " Values("
'Now the Value List
lsSelect = lsSelect & "" & Format(Company_Id) & ","
lsSelect = lsSelect & "'" & Company_Name & "',"
lsSelect = lsSelect & "'" & Address1 & "',"
lsSelect = lsSelect & "'" & Address2 & "',"
lsSelect = lsSelect & "'" & City & "',"
lsSelect = lsSelect & "'" & State & "',"
lsSelect = lsSelect & "'" & Zip & "',"
lsSelect = lsSelect & "'" & Phone & "',"
lsSelect = lsSelect & "'" & Fax & "',"
lsSelect = lsSelect & "'" & Contact & "',"
'These are the Audit Trail Fields
lsSelect = lsSelect & "'" & objConfiguration.LanId & "',"
lsSelect = lsSelect & "'" & objConfiguration.ModuleName & "',"
lsSelect = lsSelect & "#" & Format(Now, "MM/DD/YYYY hh:mm:ss") & "#)"
'Execute the SQL
dbTimeSheet.Execute lsSelect
'Reassign the original values to the properties list
RetrieveProperties
On Error GoTo 0
Exit Sub
NoCompanyAddItem:
Success = False
ErrorCode = Err
objError.ErrorCode = Err
objError.FunctionName = "clsCompany.AddItem"
If Err = 3146 Then
objError.Message = "Company, AddItem " & vbCrLf & Errors(0) & " "
ErrorMessage = Errors(0)
Else
objError.Message = "Company, AddItem "
ErrorMessage = Error(Err)
End If
objError.SQL = lsSelect
objError.Display vbExclamation
Resume Next
End Sub
'********************************************************************************************************
'Title: ClearValues
'Author: DesignGrid by W. David Ewing, Copyright 1998
'Purpose: This method clears all fields in the Table class
'Parameters:None
'Return: Nothing
'********************************************************************************************************
Sub ClearValues()
Company_Id = 0
Company_Name = ""
Address1 = ""
Address2 = ""
City = ""
State = ""
Zip = ""
Phone = ""
Fax = ""
Contact = ""
Updated_By = ""
Update_Module = ""
Update_Time = ""
End Sub
'********************************************************************************************************
'Title: DeleteItem
'Author: DesignGrid by W. David Ewing, Copyright 1998
'Purpose: This method Deletes Items from the Database after the Key fields have been filled
'Parameters:None
'Return: Nothing
'********************************************************************************************************
Public Sub DeleteItem()
Dim lrsData As Recordset
Dim RetCode As Integer, lsCount As Integer, liCount As Integer, BadCount As Integer, lsSelect As String
'The Success flag gets initialized to True and set to false if a trappable error occurs
Success = True
'The ErrorCode is the Err returned by VB for the Trapped Error
ErrorCode = False
'The DebugFlag is the provision which turns off all error checking in the table class when false
If Not objConfiguration.DebugFlag Then
On Error GoTo NoCompanyDeleteItem
End If
'First we assign all the properties to temp vars and set any blank dates to NULL, or put in the date delimiters (Database Dependent)
StoreProperties
SetDefaultDates
'Now Pad fields with a space if the record cannot be added with zero length
PadFields
'The Double Your Quotes routine doubles any single quotes in string type variables for SQL compatibility
DoubleYourQuotes
'Assemble the SQL String
lsSelect = "Delete from COMPANY where Company_Id = " & Format(Company_Id) & ""
'Execute the SQL
dbTimeSheet.Execute lsSelect
'Now ReAssign the Temp vars back to the class props
RetrieveProperties
On Error GoTo 0
Exit Sub
NoCompanyDeleteItem:
Success = False
ErrorCode = Err
objError.ErrorCode = Err
objError.FunctionName = "clsCompany.DeleteItem"
If Err = 3146 Then
objError.Message = "Company, DeleteItem " & vbCrLf & Errors(0) & " "
ErrorMessage = Errors(0)
Else
objError.Message = "Company, DeleteItem "
ErrorMessage = Error(Err)
End If
objError.SQL = lsSelect
objError.Display vbExclamation
Resume Next
End Sub
'********************************************************************************************************
'Title: FillObjectFromRecordset
'Author: DesignGrid by W. David Ewing, Copyright 1998
'Purpose This sub fills all the properties of the class from a given recordset
'Parameters:The recordset from which to fill
'Return: Nothing
'********************************************************************************************************
Public Sub FillObjectFromRecordSet(lrsData As Recordset)
Dim liCount As Integer, BadCount As Integer, psSQL As String, lsSelect As String
If Not objConfiguration.DebugFlag Then
On Error GoTo NoCompanyFillObject
End If
'Appending a & "" onto the end of a recordset field checks for Null values
'Similarly, Numbers are explicitly converted to eliminate Null values as well
Company_Id = Val(lrsData![Company_Id] & "")
Company_Name = lrsData![Company_Name] & ""
Address1 = lrsData![Address1] & ""
Address2 = lrsData![Address2] & ""
City = lrsData![City] & ""
State = lrsData![State] & ""
Zip = lrsData![Zip] & ""
Phone = lrsData![Phone] & ""
Fax = lrsData![Fax] & ""
Contact = lrsData![Contact] & ""
Updated_By = lrsData![Updated_By] & ""
Update_Module = lrsData![Update_Module] & ""
Update_Time = lrsData![Update_Time] & ""
On Error GoTo 0
Exit Sub
NoCompanyFillObject:
Success = False
ErrorCode = Err
objError.ErrorCode = Err
objError.FunctionName = "clsCompany.FillObject"
If Err = 3146 Then
objError.Message = "Company, FillObject " & vbCrLf & Errors(0) & " "
ErrorMessage = Errors(0)
Else
objError.Message = "Company, FillObject "
ErrorMessage = Error(Err)
End If
objError.SQL = lsSelect
objError.Display vbExclamation
Resume Next
End Sub
'********************************************************************************************************
'Title: GetItem
'Author: DesignGrid by W. David Ewing, Copyright 1998
'Purpose: This Method Gets a record from the database after the Key Fields have been Filled
'Parameters:The recordset from which to fill
'Return: Nothing
'********************************************************************************************************
Public Sub GetItem()
Dim lrsData As Recordset
Dim RetCode As Integer, lsCount As Integer, liCount As Integer, BadCount As Integer, lsSelect As String
'The Success flag gets initialized to True and set to false if a trappable error occurs
Success = True
'The ErrorCode is the Err returned by VB for the Trapped Error
ErrorCode = False
'The DebugFlag is the provision which turns off all error checking in the table class when false
If Not objConfiguration.DebugFlag Then
On Error GoTo NoCompanyGetItem
End If
'First we assign all the properties to temp vars and set any blank dates to NULL, or put in the date delimiters (Database Dependent)
StoreProperties
SetDefaultDates
'Now Pad fields with a space if the record cannot be added with zero length
PadFields
'The Double Your Quotes routine doubles any single quotes in string type variables for SQL compatibility
DoubleYourQuotes
'Assemble the SQL String
lsSelect = "Select * from COMPANY where Company_Id = " & Format(Company_Id) & ""
'Execute the SQL
Set lrsData = dbTimeSheet.OpenRecordset(lsSelect, dbOpenSnapshot)
'Now ReAssign the Temp vars back to the class props
RetrieveProperties
'Check for a valid record
If Not Success Then
Exit Sub
End If
If lrsData.RecordCount = 0 Then
Success = False
Exit Sub
End If
'Fill the Table Class Fields from the Recordset
FillObjectFromRecordSet lrsData
'Check for Errors
If Not Success Then
Exit Sub
End If
lrsData.Close
'Now trim the spaces out of the padded fields
TrimPaddedFields
'Strip the NULLs or bad dates out of date fields
StripDates False
On Error GoTo 0
Exit Sub
NoCompanyGetItem:
Success = False
ErrorCode = Err
objError.ErrorCode = Err
objError.FunctionName = "clsCompany.GetItem"
If Err = 3146 Then
objError.Message = "Company, GetItem " & vbCrLf & Errors(0) & " "
ErrorMessage = Errors(0)
Else
objError.Message = "Company, GetItem "
ErrorMessage = Error(Err)
End If
objError.SQL = lsSelect
objError.Display vbExclamation
Resume Next
End Sub
'********************************************************************************************************
'Title: GetNewId
'Author: DesignGrid by W. David Ewing, Copyright 1998
'Purpose: This Method Gets a new Id using the Max function in SQL, it has only limited value, but is included as
' a template for new Primary Key generation
'Parameters:None
'Return: Nothing
'********************************************************************************************************
Public Function GetNewId() As Double
Dim lrsData As Recordset
Dim RetCode As Integer, liCount As Integer, BadCount As Integer, lsSelect As String
'The Success flag gets initialized to True and set to false if a trappable error occurs
Success = True
'The ErrorCode is the Err returned by VB for the Trapped Error
ErrorCode = False
'The DebugFlag is the provision which turns off all error checking in the table class when false
If Not objConfiguration.DebugFlag Then
On Error GoTo NoCompanyGetNewId
End If
'First we assign all the date and text properties to temp vars and set any blank dates to NULL, or put in the date delimiters (Database Dependent)
StoreProperties
SetDefaultDates
'Now Pad fields with a space if the record cannot be added with zero length
PadFields
'The Double Your Quotes routine doubles any single quotes in string type variables for SQL compatibility
DoubleYourQuotes
'The SQL provided here is just a simple Get Max. This would only be useful for very small tables
'If you anticipate this table growing past a few hundred rows, change this routine accordingly
'You might try keeping a table with the last Id stored as a field, which can then be updated when a
'new Id is required.
'Assemble the SQL String
lsSelect = "Select Max(Company_Id) from COMPANY "
'Execute the SQL
Set lrsData = dbTimeSheet.OpenRecordset(lsSelect, dbOpenSnapshot)
'Now ReAssign the Temp vars back to the class props
RetrieveProperties
'Don't forget to check for those NULLS
If Not IsNull(lrsData(0)) Then
GetNewId = lrsData(0) + 1
Else
GetNewId = 1
End If
lrsData.Close
On Error GoTo 0
Exit Function
NoCompanyGetNewId:
Success = False
ErrorCode = Err
objError.ErrorCode = Err
objError.FunctionName = "clsCompany.GetNewId"
If Err = 3146 Then
objError.Message = "Company, GetNewId " & vbCrLf & Errors(0) & " "
ErrorMessage = Errors(0)
Else
objError.Message = "Company, GetNewId "
ErrorMessage = Error(Err)
End If
objError.SQL = lsSelect
objError.Display vbExclamation
Resume Next
End Function
'********************************************************************************************************
'Title: ParseItem
'Author: DesignGrid by W. David Ewing, Copyright 1998
'Purpose: This method can parse fields which have values in them. It will create an SQL criteria string
' using like statements for strings, and = statements for numbers and dates, this can be used
' in Query by Example screens with little or no modification
'Parameters:None
'Return: The Parsed String for use in SQL
'********************************************************************************************************
Public Function ParseItem(piAndFlag As Integer) As String
Dim RetCode As Integer, liCount As Integer, lsSelect As String
Dim BadCount As Integer, WildCard As String
'The Success flag gets initialized to True and set to false if a trappable error occurs
Success = True
'The ErrorCode is the Err returned by VB for the Trapped Error
ErrorCode = False
'The DebugFlag is the provision which turns off all error checking in the table class when false
If Not objConfiguration.DebugFlag Then
On Error GoTo NoCompanyParseItem
End If
'Change this based on your database, MS-Access uses the *, but SQL standard is the %
WildCard = "*'"
'First we assign all the date and text properties to temp vars and set any blank dates to NULL, or put in the date delimiters (Database Dependent)
StoreProperties
SetDefaultDates
'Now Pad fields with a space if the record cannot be added with zero length
PadFields
'The Double Your Quotes routine doubles any single quotes in string type variables for SQL compatibility
DoubleYourQuotes
If Company_Id <> 0 Then
If piAndFlag Then
lsSelect = lsSelect & " And "
Else
lsSelect = lsSelect & " Where "
End If
lsSelect = lsSelect & "Company.Company_Id = " & Format(Company_Id)
piAndFlag = True
End If
If Trim(Company_Name) <> "" Then
If piAndFlag Then
lsSelect = lsSelect & " And "
Else
lsSelect = lsSelect & " Where "
End If
lsSelect = lsSelect & "Company.Company_Name like '" & Trim(Company_Name) & WildCard
piAndFlag = True
End If
If Trim(Address1) <> "" Then
If piAndFlag Then
lsSelect = lsSelect & " And "
Else
lsSelect = lsSelect & " Where "
End If
lsSelect = lsSelect & "Company.Address1 like '" & Trim(Address1) & WildCard
piAndFlag = True
End If
If Trim(Address2) <> "" Then
If piAndFlag Then
lsSelect = lsSelect & " And "
Else
lsSelect = lsSelect & " Where "
End If
lsSelect = lsSelect & "Company.Address2 like '" & Trim(Address2) & WildCard
piAndFlag = True
End If
If Trim(City) <> "" Then
If piAndFlag Then
lsSelect = lsSelect & " And "
Else
lsSelect = lsSelect & " Where "
End If
lsSelect = lsSelect & "Company.City like '" & Trim(City) & WildCard
piAndFlag = True
End If
If Trim(State) <> "" Then
If piAndFlag Then
lsSelect = lsSelect & " And "
Else
lsSelect = lsSelect & " Where "
End If
lsSelect = lsSelect & "Company.State like '" & Trim(State) & WildCard
piAndFlag = True
End If
If Trim(Zip) <> "" Then
If piAndFlag Then
lsSelect = lsSelect & " And "
Else
lsSelect = lsSelect & " Where "
End If
lsSelect = lsSelect & "Company.Zip like '" & Trim(Zip) & WildCard
piAndFlag = True
End If
If Trim(Phone) <> "" Then
If piAndFlag Then
lsSelect = lsSelect & " And "
Else
lsSelect = lsSelect & " Where "
End If
lsSelect = lsSelect & "Company.Phone like '" & Trim(Phone) & WildCard
piAndFlag = True
End If
If Trim(Fax) <> "" Then
If piAndFlag Then
lsSelect = lsSelect & " And "
Else
lsSelect = lsSelect & " Where "
End If
lsSelect = lsSelect & "Company.Fax like '" & Trim(Fax) & WildCard
piAndFlag = True
End If
If Trim(Contact) <> "" Then
If piAndFlag Then
lsSelect = lsSelect & " And "
Else
lsSelect = lsSelect & " Where "
End If
lsSelect = lsSelect & "Company.Contact like '" & Trim(Contact) & WildCard
piAndFlag = True
End If
If Trim(Updated_By) <> "" Then
If piAndFlag Then
lsSelect = lsSelect & " And "
Else
lsSelect = lsSelect & " Where "
End If
lsSelect = lsSelect & "Company.Updated_By like '" & Trim(Updated_By) & WildCard
piAndFlag = True
End If
If Trim(Update_Module) <> "" Then
If piAndFlag Then
lsSelect = lsSelect & " And "
Else
lsSelect = lsSelect & " Where "
End If
lsSelect = lsSelect & "Company.Update_Module like '" & Trim(Update_Module) & WildCard
piAndFlag = True
End If
If IsDate(Update_Time) Then
If piAndFlag Then
lsSelect = lsSelect & " And "
Else
lsSelect = lsSelect & " Where "
End If
lsSelect = lsSelect & "Company.Update_Time = " & Update_Time
piAndFlag = True
End If
'now reassign the temp values back to the properties
RetrieveProperties
On Error GoTo 0
ParseItem = lsSelect
Exit Function
NoCompanyParseItem:
Success = False
ErrorCode = Err
objError.ErrorCode = Err
objError.FunctionName = "clsCompany.ParseItem"
If Err = 3146 Then
objError.Message = "Company, ParseItem " & vbCrLf & Errors(0) & " "
ErrorMessage = Errors(0)
Else
objError.Message = "Company, ParseItem "
ErrorMessage = Error(Err)
End If
objError.SQL = lsSelect
objError.Display vbExclamation
Resume Next
End Function
'********************************************************************************************************
'Title: UpdateItem
'Author: DesignGrid by W. David Ewing, Copyright 1998
'Purpose: This method updates a record in the database using the primary key, it is recommended that you
' Fill the Key Fields, use the get method, fill the fields which have changed,
' then call this method to perform the update
'Parameters:None
'Return: Nothing
'********************************************************************************************************
Public Sub UpdateItem()
Dim lsSelect As String
Dim RetCode As Integer, liCount As Integer, BadCount As Integer
'The Success flag gets initialized to True and set to false if a trappable error occurs
Success = True
'The ErrorCode is the Err returned by VB for the Trapped Error
ErrorCode = False
'The DebugFlag is the provision which turns off all error checking in the table class when false
If Not objConfiguration.DebugFlag Then
On Error GoTo NoCompanyUpdateItem
End If
'First we will assign the date properties to temp vars and set any blank dates to NULL, or put in the date delimiters (Database Dependent)
StoreProperties
SetDefaultDates
'Now Pad fields with a space if the record cannot be added with zero length
PadFields
'The Double Your Quotes routine doubles any single quotes in string type variables for SQL compatibility
DoubleYourQuotes
'Assemble the SQL String
lsSelect = "Update COMPANY Set "
lsSelect = lsSelect & "Company_Name = '" & Company_Name & "',"
lsSelect = lsSelect & "Address1 = '" & Address1 & "',"
lsSelect = lsSelect & "Address2 = '" & Address2 & "',"
lsSelect = lsSelect & "City = '" & City & "',"
lsSelect = lsSelect & "State = '" & State & "',"
lsSelect = lsSelect & "Zip = '" & Zip & "',"
lsSelect = lsSelect & "Phone = '" & Phone & "',"
lsSelect = lsSelect & "Fax = '" & Fax & "',"
lsSelect = lsSelect & "Contact = '" & Contact & "',"
'These are the Audit Trail Fields
lsSelect = lsSelect & "Updated_By = '" & objConfiguration.LanId & "',"
lsSelect = lsSelect & "Update_Module = '" & objConfiguration.ModuleName & "',"
lsSelect = lsSelect & "Update_Time = #" & Format(Now, "MM/DD/YYYY hh:mm:ss") & "# "
lsSelect = lsSelect & " where Company_Id = " & Format(Company_Id) & ""
'Execute the SQL
dbTimeSheet.Execute lsSelect
'now reassign the temp values back to the properties
RetrieveProperties
On Error GoTo 0
Exit Sub
NoCompanyUpdateItem:
Success = False
ErrorCode = Err
objError.ErrorCode = Err
objError.FunctionName = "clsCompany.UpdateItem"
If Err = 3146 Then
objError.Message = "Company, UpdateItem " & vbCrLf & Errors(0) & " "
ErrorMessage = Errors(0)
Else
objError.Message = "Company, UpdateItem "
ErrorMessage = Error(Err)
End If
objError.SQL = lsSelect
objError.Display vbExclamation
Resume Next
End Sub
'********************************************************************************************************
'Title: DoubleYourQuotes
'Author: DesignGrid by W. David Ewing, Copyright 1998
'Purpose: This routine Doubles your Single Quotes in all string or memo
' fields in the class for SQL compatibility
'Parameters:None
'Return: Nothing
'********************************************************************************************************
Private Sub DoubleYourQuotes()
Dim liCount As Integer, BadCount As Integer, lsSelect As String
If Not objConfiguration.DebugFlag Then
On Error GoTo NoCompanyDoubleYourQuotes
End If
'These lines double the single quotes in any string field in the class
Company_Name = SearchandDouble(Company_Name)
Address1 = SearchandDouble(Address1)
Address2 = SearchandDouble(Address2)
City = SearchandDouble(City)
State = SearchandDouble(State)
Zip = SearchandDouble(Zip)
Phone = SearchandDouble(Phone)
Fax = SearchandDouble(Fax)
Contact = SearchandDouble(Contact)
Updated_By = SearchandDouble(Updated_By)
Update_Module = SearchandDouble(Update_Module)
On Error GoTo 0
Exit Sub
NoCompanyDoubleYourQuotes:
Success = False
ErrorCode = Err
objError.ErrorCode = Err
objError.FunctionName = "clsCompany.DoubleYourQuotes"
If Err = 3146 Then
objError.Message = "Company, DoubleYourQuotes " & vbCrLf & Errors(0) & " "
ErrorMessage = Errors(0)
Else
objError.Message = "Company, DoubleYourQuotes "
ErrorMessage = Error(Err)
End If
objError.SQL = lsSelect
objError.Display vbExclamation
Resume Next
End Sub
'********************************************************************************************************
'Title: SearchandDouble
'Author: DesignGrid by W. David Ewing, Copyright 1998
'Purpose: This Function will look for any single quotes in a string passed to it
' and double them for SQL compatibility
'Parameters:string to be modified
'Return: the modified string
'********************************************************************************************************
Private Function SearchandDouble(lsBuf As String) As String
Dim liStrLen As Integer
Dim liCurChar As Integer
Dim liQuotePos As Integer
Dim lsQuote As String
Dim lsOutBuf As String
lsQuote = "'"
liCurChar = 1
lsOutBuf = ""
liQuotePos = InStr(liCurChar, lsBuf, lsQuote)
If liQuotePos = 0 Then
lsOutBuf = lsBuf
Else
liStrLen = Len(lsBuf)
Do While liQuotePos > 0
lsOutBuf = lsOutBuf & Mid(lsBuf, liCurChar, liQuotePos - liCurChar + 1) & lsQuote
liCurChar = liQuotePos + 1
liQuotePos = InStr(liCurChar, lsBuf, lsQuote)
Loop
lsOutBuf = lsOutBuf & Mid(lsBuf, liCurChar, liStrLen)
End If
SearchandDouble = lsOutBuf
End Function
'********************************************************************************************************
'Title: SetDefaultDates
'Author: DesignGrid by W. David Ewing, Copyright 1998
'Purpose: This routine puts default date or NULL into blank or invalid date fields
'Parameters:None
'Return: Nothing
'********************************************************************************************************
Private Sub SetDefaultDates()
Dim liCount As Integer, BadCount As Integer, lsSelect As String
If Not objConfiguration.DebugFlag Then
On Error GoTo NoCompanySetDefaultDates
End If
'These lines look at the dates in the class, and put a NULL or your default date
'depending on your data mode, when the date is
'blank or invalid, since this is what sql expects
If Not IsDate(Update_Time) Then
Update_Time = "NULL"
Else
Update_Time = "#" & Format(CDate(Update_Time), "MM/DD/YYYY HH:MM:SS") & "#"
End If
On Error GoTo 0
Exit Sub
NoCompanySetDefaultDates:
Success = False
ErrorCode = Err
objError.ErrorCode = Err
objError.FunctionName = "clsCompany.SetDefaultDates"
If Err = 3146 Then
objError.Message = "Company, SetDefaultDates " & vbCrLf & Errors(0) & " "
ErrorMessage = Errors(0)
Else
objError.Message = "Company, SetDefaultDates "
ErrorMessage = Error(Err)
End If
objError.SQL = lsSelect
objError.Display vbExclamation
Resume Next
End Sub
'********************************************************************************************************
'Title: StripDates
'Author: DesignGrid by W. David Ewing, Copyright 1998
'Purpose: This routine strips NULLS and bad Dates from Fields in the class, the delimiter field
' determines whether it should check for the presence of Date Delimiters
'Parameters:None
'Return: Nothing
'********************************************************************************************************
Private Sub StripDates(DelimiterFlag As Integer)
Dim liCount As Integer, BadCount As Integer, lsSelect As String
If Not objConfiguration.DebugFlag Then
On Error GoTo NoCompanyStripDates
End If
'These lines check to see if a NULL has been entered into the field from the
'DefaultDate subroutine, if it has, it is set to an empty string, the date from
'the database is also checked, if it is invalid, it to is set to an empty string
If Update_Time = "NULL" Then
Update_Time = ""
End If
On Error GoTo 0
Exit Sub
NoCompanyStripDates:
Success = False
ErrorCode = Err
objError.ErrorCode = Err
objError.FunctionName = "clsCompany.StripDates"
If Err = 3146 Then
objError.Message = "Company, StripDates " & vbCrLf & Errors(0) & " "
ErrorMessage = Errors(0)
Else
objError.Message = "Company, StripDates "
ErrorMessage = Error(Err)
End If
objError.SQL = lsSelect
objError.Display vbExclamation
Resume Next
End Sub
'********************************************************************************************************
'Title: PadFields
'Author: DesignGrid by W. David Ewing, Copyright 1998
'Purpose: This routine Pads any fields with a space which do not allow zero length
'Purpose: The Allow zero length property is set by default in Access databases and is
' used also in Oracle and SQLServer if the if fields are not padded with space
' the database won't add the record, sometimes this is desirable sometimes not
'Parameters:None
'Return: Nothing
'********************************************************************************************************
Private Sub PadFields()
Dim liCount As Integer, BadCount As Integer, lsSelect As String
If Not objConfiguration.DebugFlag Then
On Error GoTo NoCompanyPadFields
End If
'These lines put a space into any field which does not allow zero length, so the
'record can be added anyway
If Trim(Contact) = "" Then
Contact = " "
End If
On Error GoTo 0
Exit Sub
NoCompanyPadFields:
Success = False
ErrorCode = Err
objError.ErrorCode = Err
objError.FunctionName = "clsCompany.PadFields"
If Err = 3146 Then
objError.Message = "Company, PadFields " & vbCrLf & Errors(0) & " "
ErrorMessage = Errors(0)
Else
objError.Message = "Company, PadFields "
ErrorMessage = Error(Err)
End If
objError.SQL = lsSelect
objError.Display vbExclamation
Resume Next
End Sub
'********************************************************************************************************
'Title: TrimPaddedFields
'Author: DesignGrid by W. David Ewing, Copyright 1998
'Purpose: This routine Trims the fields which have spaces at beginning or end
'Parameters:None
'Return: Nothing
'********************************************************************************************************
Private Sub TrimPaddedFields()
Dim liCount As Integer, BadCount As Integer, lsSelect As String
If Not objConfiguration.DebugFlag Then
On Error GoTo NoCompanyTrimPaddedFields
End If
'This routine deletes the spaces from any padded fields
Contact = Trim(Contact)
On Error GoTo 0
Exit Sub
NoCompanyTrimPaddedFields:
Success = False
ErrorCode = Err
objError.ErrorCode = Err
objError.FunctionName = "clsCompany.TrimPaddedFields"
If Err = 3146 Then
objError.Message = "Company, TrimPaddedFields " & vbCrLf & Errors(0) & " "
ErrorMessage = Errors(0)
Else
objError.Message = "Company, TrimPaddedFields "
ErrorMessage = Error(Err)
End If
objError.SQL = lsSelect
objError.Display vbExclamation
Resume Next
End Sub
'********************************************************************************************************
'Title: StoreProperties
'Author: DesignGrid by W. David Ewing, Copyright 1998
'Purpose This Sub Assigns the Properties of the Class to the
' private class scratchpad variables
'Parameters:None
'Return: Nothing
'********************************************************************************************************
Private Sub StoreProperties()
mCompany_Id = Company_Id
mCompany_Name = Company_Name
mAddress1 = Address1
mAddress2 = Address2
mCity = City
mState = State
mZip = Zip
mPhone = Phone
mFax = Fax
mContact = Contact
mUpdated_By = Updated_By
mUpdate_Module = Update_Module
mUpdate_Time = Update_Time
End Sub
'********************************************************************************************************
'Title: RetrieveProperties
'Author: DesignGrid by W. David Ewing, Copyright 1998
'Purpose This Sub Assigns the ScratchPad Variable Values back to the Class properties
'Parameters:None
'Return: Nothing
'********************************************************************************************************
Private Sub RetrieveProperties()
Company_Id = mCompany_Id
Company_Name = mCompany_Name
Address1 = mAddress1
Address2 = mAddress2
City = mCity
State = mState
Zip = mZip
Phone = mPhone
Fax = mFax
Contact = mContact
Updated_By = mUpdated_By
Update_Module = mUpdate_Module
Update_Time = mUpdate_Time
End Sub